package cn.tedu.egmvc2.controller;

import cn.tedu.egmvc2.mapper.AddressMapper;
import cn.tedu.egmvc2.pojo.dto.addressDTO;
import cn.tedu.egmvc2.pojo.entity.Address;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
public class addressController {
    @Autowired
    private AddressMapper addressMapper;
//    @RequestMapping(value="/insert", method = RequestMethod.POST)
    @PostMapping("/insert")
    public String addressinsert(addressDTO addressDTO){
        Address address = new Address();
        BeanUtils.copyProperties(addressDTO, address);
        addressMapper.insertAddress(address);

        return "添加成功！";
    }

    @GetMapping("/select")
    public List< Address> addressselect(){
       return addressMapper.selectAddress();

    }

    @GetMapping("/delete")
    public String addressdelete(Integer id){
        addressMapper.deleteAddress(id);
        return "删除成功！";
    }
    @PostMapping("/update")
    public String addressupdate(Address address){
        addressMapper.updateAddress(address);
        return "修改成功！";
    }
}
